﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;
using System.IO;
using AssemblyCYG.参数模块;

namespace AssemblyCYG
{
    public partial class SetParaForm : Form
    {
        HalconAlgorithm halconAlgorithm = new HalconAlgorithm();
        HObject ho_reviewLowImage = null;
        HObject ho_reviewHighImage = null;
        System.Diagnostics.Stopwatch detectTime = new System.Diagnostics.Stopwatch();
        double coilReviewFitCircle1_X = 0;
        double coilReviewFitCircle1_Y = 0;
        double coidReviewLineCorner_X = 0;
        double coidReviewLineCorner_Y = 0;
        double coilReviewFitCircle2_X = 0;
        double coilReviewFitCircle2_Y = 0;

        double coilReviewFitLineS_X = 0;
        double coilReviewFitLineS_Y = 0;
        double coilReviewFitLineE_X = 0;
        double coilReviewFitLineE_Y = 0;
        HTuple hv_HomMat2DCoilReview2;

        public SetParaForm()
        {
            InitializeComponent();
            HOperatorSet.SetDraw(hWindowControl1.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl1.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl2.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl2.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl3.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl3.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl4.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl4.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl_coilReview1.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl_coilReview1.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl_coilReview2.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl_coilReview2.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl_coilReview3.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl_coilReview3.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl_springGlue.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl_springGlue.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl_coilGlue.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl_coilGlue.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl5.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl5.HalconWindow, 2);
            HOperatorSet.SetDraw(hWindowControl_upCam2.HalconWindow, "margin");
            HOperatorSet.SetLineWidth(hWindowControl_upCam2.HalconWindow, 2);

            HOperatorSet.GenEmptyObj(out ho_reviewLowImage);
            HOperatorSet.GenEmptyObj(out ho_reviewHighImage);
            LoadDetectPara();
            InitialControlsShow();
        }
        private void InitialControlsShow()
        {
            switch (ShareData.projectItem)
            {
                case ShareData.ItemType.手动线组装:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_robotGuide);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilReview);
                    break;
                case ShareData.ItemType.自动线spring组装:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_springReview);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilReview);
                    break;
                case ShareData.ItemType.自动线coil组装:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_springReview);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilReview);
                    this.panel_spring1.Visible = false;
                    this.panel_spring2.Visible = false;
                    break;
                case ShareData.ItemType.spring自检:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_upCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_downCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_robotGuide);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilReview);
                    break;
                case ShareData.ItemType.coil自检:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_upCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_downCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_robotGuide);
                    this.tabControl1.TabPages.Remove(this.tabPage_springReview);
                    this.panel_spring1.Visible = false;
                    this.panel_spring2.Visible = false;
                    break;
                case ShareData.ItemType.spring胶形检测:
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_upCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_downCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_robotGuide);
                    this.tabControl1.TabPages.Remove(this.tabPage_springReview);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilReview);
                    break;
                case ShareData.ItemType.coil胶形检测:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_upCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_downCam);
                    this.tabControl1.TabPages.Remove(this.tabPage_robotGuide);
                    this.tabControl1.TabPages.Remove(this.tabPage_springReview);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilReview);
                    break;
                case ShareData.ItemType.coil半自动线:
                    this.tabControl1.TabPages.Remove(this.tabPage_springGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_coilGlue);
                    this.tabControl1.TabPages.Remove(this.tabPage_robotGuide);
                    this.tabControl1.TabPages.Remove(this.tabPage_springReview);
                    this.panel_spring1.Visible = false;
                    this.panel_spring2.Visible = false;
                    btn_setCoilReviewCircle4.Visible = false;

                    break;
            }
        }
        private void LoadDetectPara()
        {
            this.tB_coilReviewCornerStart.Text = ProjectInfo.Parameter.coilReviewLineCornerStartPhi.ToString();
            this.tB_coilReviewCornerEnd.Text = ProjectInfo.Parameter.coilReviewLineCornerEndPhi.ToString();
            this.tB_coilReviewOutCircleRadius.Text = ProjectInfo.Parameter.coilReviewOutCircleRadius.ToString();

            this.tB_upCamOutCircleRadius.Text = ProjectInfo.Parameter.upCamLocateOutCircleRadius.ToString();
            this.tB_upCamOutCircleRadius2.Text = ProjectInfo.Parameter.upCamLocateOutCircleRadius2.ToString();
            this.tB_downCamOutCircleRadius.Text = ProjectInfo.Parameter.downCamLocateOutCircleRadius.ToString();
            this.tB_reviewPuckOutCircleRadius.Text = ProjectInfo.Parameter.reviewPartOutCircleRadius.ToString();
            this.tB_reviewSpringOutCircleRadius.Text = ProjectInfo.Parameter.reviewSpringOutCircleRadius.ToString();
            this.tB_upCamSeekStartPhi.Text = ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi.ToString();
            this.tB_upCamSeekEndPhi.Text = ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi.ToString();

            this.tB_upCamSeekStartPhi2.Text = ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi2.ToString();
            this.tB_upCamSeekEndPhi2.Text = ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi2.ToString();

            this.tB_downCamSeekStartPhi.Text = ProjectInfo.Parameter.downCamLocateSeekCornerStartPhi.ToString();
            this.tB_downCamSeekEndPhi.Text = ProjectInfo.Parameter.downCamLocateSeekCornerEndPhi.ToString();
            this.tB_reviewSeekStartPhi.Text = ProjectInfo.Parameter.reviewSeekCornerStartPhi.ToString();
            this.tB_reviewSeekEndPhi.Text = ProjectInfo.Parameter.reviewSeekCornerEndPhi.ToString();

            this.tB_socketIpAddress.Text = ProjectInfo.Parameter.tcpIpAddress;
            this.socketPort.Value = ProjectInfo.Parameter.tcpPort;
            this.tB_MaxAngleOffset.Text = ProjectInfo.Parameter.maxAngleOffset.ToString();
            this.tB_MaxXOffset.Text = ProjectInfo.Parameter.maxXOffset.ToString();
            this.tB_MaxYOffset.Text = ProjectInfo.Parameter.maxYOffset.ToString();
            this.tB_buChangAngle1.Text = ProjectInfo.Parameter.buChang_Angle1.ToString();
            this.tB_buChangX1.Text = ProjectInfo.Parameter.buChang_X1.ToString();
            this.tB_buChangY1.Text = ProjectInfo.Parameter.buChang_Y1.ToString();

            this.tB_buChangAngle2.Text = ProjectInfo.Parameter.buChang_Angle2.ToString();
            this.tB_buChangX2.Text = ProjectInfo.Parameter.buChang_X2.ToString();
            this.tB_buChangY2.Text = ProjectInfo.Parameter.buChang_Y2.ToString();

            this.tB_OKRotateAngle.Text = ProjectInfo.Parameter.oKRotateAngle.ToString();
            this.btn_reviewMaxPosOffset.Text = ProjectInfo.Parameter.reviewMaxPosOffset.ToString();
            this.btn_reviewMaxAngleOffset.Text = ProjectInfo.Parameter.reviewMaxAngleOffset.ToString();
            this.tB_scannerIpAddress.Text = ProjectInfo.Parameter.scannerIpAddress;

            this.tB_simoROI1R1.Text = ProjectInfo.Parameter.simoROI1R1.ToString();
            this.tB_simoROI1C1.Text = ProjectInfo.Parameter.simoROI1C1.ToString();
            this.tB_simoROI1R2.Text = ProjectInfo.Parameter.simoROI1R2.ToString();
            this.tB_simoROI1C2.Text = ProjectInfo.Parameter.simoROI1C2.ToString();

            this.tB_simoROI2R1.Text = ProjectInfo.Parameter.simoROI2R1.ToString();
            this.tB_simoROI2C1.Text = ProjectInfo.Parameter.simoROI2C1.ToString();
            this.tB_simoROI2R2.Text = ProjectInfo.Parameter.simoROI2R2.ToString();
            this.tB_simoROI2C2.Text = ProjectInfo.Parameter.simoROI2C2.ToString();

            if (ProjectInfo.Parameter.saveImagePath != "")
                this.tB_savePath.Text = ProjectInfo.Parameter.saveImagePath;
            else
                this.tB_savePath.Text = "D:\\saveImage";
            this.nUD_saveImageDays.Value = ProjectInfo.Parameter.saveImageDays;
            if (ProjectInfo.Parameter.saveImageType > -1)
                this.cB_saveImageType.SelectedIndex = ProjectInfo.Parameter.saveImageType;
            else
                this.cB_saveImageType.SelectedIndex = 0;
            if (ProjectInfo.Parameter.saveImageFormat > -1)
                this.cB_saveImageFormat.SelectedIndex = ProjectInfo.Parameter.saveImageFormat;
            else
                this.cB_saveImageFormat.SelectedIndex = 0;
            if (ProjectInfo.Parameter.isSaveDetectImage)
                this.cB_saveDetectImage.Checked = true;
            else
                this.cB_saveDetectImage.Checked = false;
            if (ProjectInfo.Parameter.isSaveReport)
                this.cB_isOutputReport.Checked = true;
            else
                this.cB_isOutputReport.Checked = false;
            if (ProjectInfo.Parameter.saveReportPath != "")
                this.tB_saveReportPath.Text = ProjectInfo.Parameter.saveReportPath;
            else
                this.tB_saveReportPath.Text = "D:\\saveImage";
            string upMsopPath = System.Environment.CurrentDirectory + "\\MSOP\\up.jpg";
            if (File.Exists(upMsopPath))
            {
                Bitmap showImage = new Bitmap(upMsopPath);
                this.pictureBox_upMsop.Image = showImage;
            }
            string downMsopPath = System.Environment.CurrentDirectory + "\\MSOP\\down.jpg";
            if (File.Exists(downMsopPath))
            {
                Bitmap showImage = new Bitmap(downMsopPath);
                this.pictureBox_downMsop.Image = showImage;
            }

            tbOuterRadius.Text = ProjectInfo.Parameter.outerRadius.ToString();
            tbInnerRadius.Text = ProjectInfo.Parameter.innerRadius.ToString();
        }

        #region 上相机定位1参数设置
        private void btn_upCamLocateMatch_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.upCamLocateMatchPara == null) ProjectInfo.Parameter.upCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "upCamLocate");
            MatchForm matchForm = new MatchForm(ProjectInfo.Parameter.upCamLocateMatchPara, modelImageFold);
            matchForm.ShowDialog();
            ProjectInfo.Parameter.upCamLocateMatchPara.modelLocationCol = matchForm.outMatchPara.modelLocationCol;
            ProjectInfo.Parameter.upCamLocateMatchPara.modelLocationRow = matchForm.outMatchPara.modelLocationRow;
            ProjectInfo.Parameter.upCamLocateMatchPara.modelMatchType = matchForm.outMatchPara.modelMatchType;
            ProjectInfo.Parameter.upCamLocateMatchPara.seekAngleRange = matchForm.outMatchPara.seekAngleRange;
            ProjectInfo.Parameter.upCamLocateMatchPara.seekAngleStart = matchForm.outMatchPara.seekAngleStart;
            ProjectInfo.Parameter.upCamLocateMatchPara.seekModelNum = matchForm.outMatchPara.seekModelNum;
            ProjectInfo.Parameter.upCamLocateMatchPara.seekModelScore = matchForm.outMatchPara.seekModelScore;
        }
        private void btn_SeetUpCamLocateFitCircle_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.upCamLocateFitCirclePara == null) ProjectInfo.Parameter.upCamLocateFitCirclePara = new FitCirclePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//circle.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.upCamLocateFitCirclePara, hv_region);
            fitCircleForm.SetBlobLocate(10, 35, 34, 66);                               //设置blob定位

            fitCircleForm.ShowDialog();
            //fitCircleForm.hv_saveRegion.WriteObject(regionFile);                 //保存roi
            ProjectInfo.Parameter.upCamLocateFitCirclePara.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.upCamLocateFitCirclePara.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.upCamLocateFitCirclePara.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI;
            ProjectInfo.Parameter.upCamLocateFitCirclePara.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.upCamLocateFitCirclePara.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.upCamLocateFitCirclePara.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.upCamLocateFitCirclePara.sigma = fitCircleForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.upCamLocateFitCirclePara.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;
            hv_region.Dispose();
        }
        private void btn_SetUpCamLocateFitLine1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.upCamLocateFitLine1Para == null) ProjectInfo.Parameter.upCamLocateFitLine1Para = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//line1.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.upCamLocateFitLine1Para, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.upCamLocateFitLine1Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.upCamLocateFitLine1Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.upCamLocateFitLine1Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }
        private void btn_SetUpCamLocateFitLine2_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.upCamLocateFitLine2Para == null) ProjectInfo.Parameter.upCamLocateFitLine2Para = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//line2.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.upCamLocateFitLine2Para, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.upCamLocateFitLine2Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.upCamLocateFitLine2Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.upCamLocateFitLine2Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }
        private void btn_loadImageAndProcess_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                halconAlgorithm.innerRadius = ProjectInfo.Parameter.innerRadius;
                halconAlgorithm.outerRadius = ProjectInfo.Parameter.outerRadius;

                this.tB_upCamImagePath.Text = openFileDialog.FileName;
                HObject ho_Image = null;
                HObject ho_fitCircleContour = null;
                HObject ho_fitLine1Contour = null;
                HObject ho_fitLine2Contour = null;
                HObject ho_fitAngleLine = null;
                HTuple hv_ImageWidth, hv_ImageHeight = null;
                HOperatorSet.GenEmptyObj(out ho_Image);
                ho_Image.Dispose();
                HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                double circle_X = 0;
                double circle_Y = 0;
                double lineCorner_X = 0;
                double lineCorner_Y = 0;
                double angle = 0;
                string bugInfo = "";
                //int countROI = 0;
                HObject upCamROI_circle = null;
                HObject upCamROI_line1 = null;
                HObject upCamROI_line2 = null;
                HOperatorSet.GenEmptyObj(out upCamROI_circle);
                HOperatorSet.GenEmptyObj(out upCamROI_line1);
                HOperatorSet.GenEmptyObj(out upCamROI_line2);
                string upCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//circle.hobj";
                if (File.Exists(upCircleFile)) upCamROI_circle.ReadObject(upCircleFile);           //读取roi
                else
                {
                    MessageBox.Show("上相机circleRegion为空！");
                    return;
                }
                string upLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//line1.hobj";
                if (File.Exists(upLine1File)) upCamROI_line1.ReadObject(upLine1File);            //读取roi
                else
                {
                    MessageBox.Show("上相机line1Region为空！");
                    return;
                }

                string upLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//line2.hobj";
                if (File.Exists(upLine2File)) upCamROI_line2.ReadObject(upLine2File);            //读取roi
                else
                {
                    MessageBox.Show("上相机line2Region为空！");
                    return;
                }
                double outCircleRadius = 0;

                outCircleRadius = ProjectInfo.Parameter.upCamLocateOutCircleRadius / ShareData.upCamPixSize1;      //流道1
                //流道2
                detectTime.Reset();
                detectTime.Start();

                halconAlgorithm.GetCoilPuckLocateROI(ho_Image, out upCamROI_circle);
                if (halconAlgorithm.GetPuckPosition(ho_Image, ProjectInfo.Parameter.upCamLocateFitCirclePara,
                    ProjectInfo.Parameter.upCamLocateFitLine1Para, ProjectInfo.Parameter.upCamLocateFitLine2Para,
                    upCamROI_circle, upCamROI_line1, upCamROI_line2, ProjectInfo.Parameter.upCamLocateOutCircleRadius / ShareData.upCamPixSize1,
                    ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi, ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi,
                    out ho_fitCircleContour, out ho_fitLine1Contour, out ho_fitLine2Contour,
                    out ho_fitAngleLine, out circle_X, out circle_Y, out lineCorner_X, out lineCorner_Y, out angle, out bugInfo))
                {
                    halconAlgorithm.ho_AdaptiveImage(hWindowControl1, hv_ImageWidth, hv_ImageHeight);
                    hWindowControl1.HalconWindow.ClearWindow();
                    HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
                    HOperatorSet.SetColor(hWindowControl1.HalconWindow, "blue");
                    HOperatorSet.DispObj(ho_fitAngleLine, hWindowControl1.HalconWindow);
                    HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl1.HalconWindow);
                    HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl1.HalconWindow);
                    HOperatorSet.DispObj(ho_fitLine2Contour, hWindowControl1.HalconWindow);
                    this.tB_upLocatePoint_X.Text = circle_X.ToString("f3");
                    this.tB_upLocatePoint_Y.Text = circle_Y.ToString("f3");
                    this.tB_upLocateAngle.Text = angle.ToString("f3");
                }
                else
                {
                    MessageBox.Show("检测失败！" + bugInfo);
                }
                ho_Image.Dispose();
                ho_fitAngleLine.Dispose();
                ho_fitCircleContour.Dispose();
                ho_fitLine1Contour.Dispose();
                ho_fitLine2Contour.Dispose();
                detectTime.Stop();
                this.tB_upCamDetectTime.Text = detectTime.ElapsedMilliseconds.ToString();
            }
        }
        #endregion

        #region 下相机定位参数
        private void btn_downCamLocateMatch_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.downCamLocateMatchPara == null) ProjectInfo.Parameter.downCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
            MatchForm matchForm = new MatchForm(ProjectInfo.Parameter.downCamLocateMatchPara, modelImageFold);
            matchForm.ShowDialog();
            ProjectInfo.Parameter.downCamLocateMatchPara.modelLocationCol = matchForm.outMatchPara.modelLocationCol;
            ProjectInfo.Parameter.downCamLocateMatchPara.modelLocationRow = matchForm.outMatchPara.modelLocationRow;
            ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType = matchForm.outMatchPara.modelMatchType;
            ProjectInfo.Parameter.downCamLocateMatchPara.seekAngleRange = matchForm.outMatchPara.seekAngleRange;
            ProjectInfo.Parameter.downCamLocateMatchPara.seekAngleStart = matchForm.outMatchPara.seekAngleStart;
            ProjectInfo.Parameter.downCamLocateMatchPara.seekModelNum = matchForm.outMatchPara.seekModelNum;
            ProjectInfo.Parameter.downCamLocateMatchPara.seekModelScore = matchForm.outMatchPara.seekModelScore;
        }

        private void btn_SeetDownCamLocateFitCircle_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.downCamLocateFitCirclePara == null) ProjectInfo.Parameter.downCamLocateFitCirclePara = new FitCirclePara();
            if (ProjectInfo.Parameter.downCamLocateMatchPara == null) ProjectInfo.Parameter.downCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//circle.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.downCamLocateFitCirclePara, hv_region);
            fitCircleForm.LoadMatchPara(modelImageFold, ProjectInfo.Parameter.downCamLocateMatchPara);
            fitCircleForm.ShowDialog();
            fitCircleForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.downCamLocateFitCirclePara.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.downCamLocateFitCirclePara.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.downCamLocateFitCirclePara.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI.Clone();
            ProjectInfo.Parameter.downCamLocateFitCirclePara.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.downCamLocateFitCirclePara.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.downCamLocateFitCirclePara.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.downCamLocateFitCirclePara.sigma = fitCircleForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.downCamLocateFitCirclePara.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_SetDownCamLocateFitLine1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.downCamLocateFitLine1Para == null) ProjectInfo.Parameter.downCamLocateFitLine1Para = new FitLinePara();
            if (ProjectInfo.Parameter.downCamLocateMatchPara == null) ProjectInfo.Parameter.downCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//line1.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.downCamLocateFitLine1Para, hv_region);
            fitLineForm.LoadMatchPara(modelImageFold, ProjectInfo.Parameter.downCamLocateMatchPara);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.downCamLocateFitLine1Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.downCamLocateFitLine1Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.downCamLocateFitLine1Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            //hv_region.Dispose();
        }

        private void btn_SetDownCamLocateFitLine2_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.downCamLocateFitLine2Para == null) ProjectInfo.Parameter.downCamLocateFitLine2Para = new FitLinePara();
            if (ProjectInfo.Parameter.downCamLocateMatchPara == null) ProjectInfo.Parameter.downCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//line2.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.downCamLocateFitLine2Para, hv_region);
            fitLineForm.LoadMatchPara(modelImageFold, ProjectInfo.Parameter.downCamLocateMatchPara);      //加载匹配参数
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);                      //写入roi
            ProjectInfo.Parameter.downCamLocateFitLine2Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.downCamLocateFitLine2Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.downCamLocateFitLine2Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_loadDownImageAndProcess_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.tB_downCamImagePath.Text = openFileDialog.FileName;
                HObject ho_Image = null;
                HObject ho_fitCircleContour = null;
                HObject ho_fitLine1Contour = null;
                HTuple hv_ImageWidth, hv_ImageHeight = null;
                HOperatorSet.GenEmptyObj(out ho_Image);
                ho_Image.Dispose();
                HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                double circle_X = 0;
                double circle_Y = 0;
                double angle = 0;
                string bugInfo = "";
                HTuple hv_matchModel = null;
                string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
                if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 0)   //基于形状
                {
                    string shapeModelFile = modelImageFold + "\\model.shm";
                    if (!File.Exists(shapeModelFile))
                    {
                        MessageBox.Show("模板文件不存在，请先加载模型！");
                        return;
                    }
                    HOperatorSet.ReadShapeModel(shapeModelFile, out hv_matchModel);  //加载模板
                }
                else if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 1)  //基于灰度
                {
                    string nccModelFile = modelImageFold + "\\model.ncm";
                    if (!File.Exists(nccModelFile))
                    {
                        MessageBox.Show("模板文件不存在，请先加载模型！");
                        return;
                    }
                    HOperatorSet.ReadNccModel(nccModelFile, out hv_matchModel);  //加载模板
                }
                HObject downCamROI_circle = null;
                HObject downCamROI_line1 = null;
                HObject downCamROI_line2 = null;
                HOperatorSet.GenEmptyObj(out downCamROI_circle);
                HOperatorSet.GenEmptyObj(out downCamROI_line1);
                HOperatorSet.GenEmptyObj(out downCamROI_line2);
                string downCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//circle.hobj";
                if (File.Exists(downCircleFile)) downCamROI_circle.ReadObject(downCircleFile);           //读取roi
                else
                {
                    MessageBox.Show("下相机circleRegion为空！");
                    return;
                }
                string downLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//line1.hobj";
                if (File.Exists(downLine1File)) downCamROI_line1.ReadObject(downLine1File);           //读取roi
                else
                {
                    MessageBox.Show("下相机line1Region为空！");
                    return;
                }
                detectTime.Reset();
                detectTime.Start();
                if (ShareData.projectItem == ShareData.ItemType.自动线coil组装 || ShareData.projectItem == ShareData.ItemType.coil半自动线)
                {
                    if (halconAlgorithm.GetCoilPosition_match(ho_Image, hv_matchModel, ProjectInfo.Parameter.downCamLocateMatchPara, ProjectInfo.Parameter.downCamLocateFitCirclePara,
                                ProjectInfo.Parameter.downCamLocateFitLine1Para, downCamROI_circle, downCamROI_line1, out ho_fitCircleContour, out ho_fitLine1Contour, out circle_X, out circle_Y, out angle, out bugInfo))
                    {
                        halconAlgorithm.ho_AdaptiveImage(hWindowControl2, hv_ImageWidth, hv_ImageHeight);
                        hWindowControl2.HalconWindow.ClearWindow();
                        HOperatorSet.DispObj(ho_Image, hWindowControl2.HalconWindow);
                        HOperatorSet.SetColor(hWindowControl2.HalconWindow, "blue");
                        HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl2.HalconWindow);
                        HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl2.HalconWindow);
                        this.tB_downLocatePoint_X.Text = circle_X.ToString("f4");
                        this.tB_downLocatePoint_Y.Text = circle_Y.ToString("f4");
                        this.tB_downLocateAngle.Text = angle.ToString("f4");
                    }
                    else
                    {
                        MessageBox.Show(bugInfo);
                    }
                }

                #region 下相机撕膜算法
                try
                {
                    HTuple hv_result = null;
                    HTuple hv_gray = null;
                    HObject ho_SiMoROI = null;
                    halconAlgorithm.JudgeTapeExist(ho_Image, hv_matchModel, ProjectInfo.Parameter.downCamLocateMatchPara, out hv_result, out hv_gray, out ho_SiMoROI);
                    if (ho_SiMoROI != null)
                    {
                        HOperatorSet.DispObj(ho_SiMoROI, this.hWindowControl2.HalconWindow);
                    }

                    if (hv_result == 0)   //增加撕膜算法
                    {
                        //膜已撕掉
                        pnl_siMo.BackColor = Color.Lime;
                        this.lab_gray.Text = hv_gray.D.ToString("f2");
                        HOperatorSet.SetColor(this.hWindowControl2.HalconWindow, "cyan");
                        HOperatorSet.DispObj(ho_SiMoROI, this.hWindowControl2.HalconWindow);
                    }
                    else
                    {
                        //膜未撕掉
                        this.Invoke(new Action(() =>
                        {
                            pnl_siMo.BackColor = Color.Red;
                            this.lab_gray.Text = hv_gray.D.ToString("f2");
                            HOperatorSet.SetColor(this.hWindowControl2.HalconWindow, "orange");
                            HOperatorSet.DispObj(ho_SiMoROI, this.hWindowControl2.HalconWindow);

                        }));
                    }
                    ho_SiMoROI.Dispose();
                    hv_result.Dispose();
                    hv_gray.Dispose();
                }
                catch (Exception ex)
                {
                    pnl_siMo.BackColor = Color.Yellow;
                    this.lab_gray.Text = "Error";
                }

                #endregion


                ho_fitCircleContour.Dispose();
                ho_fitLine1Contour.Dispose();
                detectTime.Stop();
                this.tB_downCamDetectTime.Text = detectTime.ElapsedMilliseconds.ToString();
                if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 0)   //基于形状
                {
                    HOperatorSet.ClearShapeModel(hv_matchModel);                     //清除模板
                }
                else if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 1)  //基于灰度
                {
                    HOperatorSet.ClearNccModel(hv_matchModel);                   //清除模板
                }
            }
        }

        #endregion

        #region 复检参数
        private void btn_SetReviewHighFitCircle_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.reviewHighFitCirclePara == null) ProjectInfo.Parameter.reviewHighFitCirclePara = new FitCirclePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//circle.hobj";   //二次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.reviewHighFitCirclePara, hv_region);
            fitCircleForm.ShowDialog();
            fitCircleForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.reviewHighFitCirclePara.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.reviewHighFitCirclePara.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.reviewHighFitCirclePara.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI;
            ProjectInfo.Parameter.reviewHighFitCirclePara.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.reviewHighFitCirclePara.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.reviewHighFitCirclePara.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.reviewHighFitCirclePara.sigma = fitCircleForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.reviewHighFitCirclePara.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;
            hv_region.Dispose();
        }
        private void btn_SetReviewLowFitCircle_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.reviewLowFitCirclePara == null) ProjectInfo.Parameter.reviewLowFitCirclePara = new FitCirclePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//circle.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.reviewLowFitCirclePara, hv_region);
            fitCircleForm.ShowDialog();
            fitCircleForm.hv_saveRegion.WriteObject(regionFile);                     //保存roi
            ProjectInfo.Parameter.reviewLowFitCirclePara.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.reviewLowFitCirclePara.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.reviewLowFitCirclePara.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI;
            ProjectInfo.Parameter.reviewLowFitCirclePara.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.reviewLowFitCirclePara.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.reviewLowFitCirclePara.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.reviewLowFitCirclePara.sigma = fitCircleForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.reviewLowFitCirclePara.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_SetReviewLowFitLine1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.reviewLowSpringLine1Para == null) ProjectInfo.Parameter.reviewLowSpringLine1Para = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//line1.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.reviewLowSpringLine1Para, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.reviewLowSpringLine1Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.reviewLowSpringLine1Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.reviewLowSpringLine1Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_SetReviewLowFitLine2_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.reviewLowSpringLine2Para == null) ProjectInfo.Parameter.reviewLowSpringLine2Para = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//line2.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.reviewLowSpringLine2Para, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.reviewLowSpringLine2Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.reviewLowSpringLine2Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.reviewLowSpringLine2Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_SetReviewPartLine1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.reviewLowPartLine1Para == null) ProjectInfo.Parameter.reviewLowPartLine1Para = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line1.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.reviewLowPartLine1Para, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.reviewLowPartLine1Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.reviewLowPartLine1Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.reviewLowPartLine1Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.reviewLowPartLine1Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.reviewLowPartLine1Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.reviewLowPartLine1Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.reviewLowPartLine1Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.reviewLowPartLine1Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.reviewLowPartLine1Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_SetReviewPartLine2_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.reviewLowPartLine2Para == null) ProjectInfo.Parameter.reviewLowPartLine2Para = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line2.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.reviewLowPartLine2Para, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.reviewLowPartLine2Para.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.reviewLowPartLine2Para.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.reviewLowPartLine2Para.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.reviewLowPartLine2Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.reviewLowPartLine2Para.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.reviewLowPartLine2Para.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.reviewLowPartLine2Para.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.reviewLowPartLine2Para.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.reviewLowPartLine2Para.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_loadReviewLowImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.tB_reviewLowImagePath.Text = openFileDialog.FileName;
                HTuple hv_ImageWidth, hv_ImageHeight = null;
                ho_reviewLowImage.Dispose();
                HOperatorSet.ReadImage(out ho_reviewLowImage, openFileDialog.FileName);    //加载图像
                HOperatorSet.GetImageSize(ho_reviewLowImage, out hv_ImageWidth, out hv_ImageHeight);
                halconAlgorithm.ho_AdaptiveImage(hWindowControl4, hv_ImageWidth, hv_ImageHeight);
                hWindowControl4.HalconWindow.ClearWindow();
                HOperatorSet.DispObj(ho_reviewLowImage, hWindowControl4.HalconWindow);
            }
        }

        private void button2btn_loadReviewHighImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.tB_reviewHighImagePath.Text = openFileDialog.FileName;
                HTuple hv_ImageWidth, hv_ImageHeight = null;
                ho_reviewHighImage.Dispose();
                HOperatorSet.ReadImage(out ho_reviewHighImage, openFileDialog.FileName);    //加载图像
                HOperatorSet.GetImageSize(ho_reviewHighImage, out hv_ImageWidth, out hv_ImageHeight);
                halconAlgorithm.ho_AdaptiveImage(hWindowControl3, hv_ImageWidth, hv_ImageHeight);
                hWindowControl3.HalconWindow.ClearWindow();
                HOperatorSet.DispObj(ho_reviewHighImage, hWindowControl3.HalconWindow);
            }
        }

        private void btn_testReview_Click(object sender, EventArgs e)
        {
            if (ho_reviewLowImage != null && ho_reviewHighImage != null)
            {
                HObject ho_fitPartCircleContour = null;
                HObject ho_fitSpringCircleContour = null;
                HObject ho_fitPartLine1Contour = null;
                HObject ho_fitPartLine2Contour = null;
                HObject ho_fitSpringLine1Contour = null;
                HObject ho_fitSpringLine2Contour = null;
                HObject ho_fitPartLine = null;
                HObject ho_fitSpringLine = null;
                HObject ho_circleDisLine = null;
                double disOfTwoCircle = 0;
                double Offset_X = 0;
                double Offset_Y = 0;
                double offset_Angle = 0;
                string bugInfo = "";
                //加载检测region
                HObject puckCircleRegion = null;
                HObject puckLine1Region = null;
                HObject puckLine2Region = null;
                HObject springCircleRegion = null;
                HObject springLine1Region = null;
                HObject springLine2Region = null;
                HOperatorSet.GenEmptyObj(out puckCircleRegion);
                HOperatorSet.GenEmptyObj(out puckLine1Region);
                HOperatorSet.GenEmptyObj(out puckLine2Region);
                HOperatorSet.GenEmptyObj(out springCircleRegion);
                HOperatorSet.GenEmptyObj(out springLine1Region);
                HOperatorSet.GenEmptyObj(out springLine2Region);
                string puckCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//circle.hobj";
                if (File.Exists(puckCircleFile)) puckCircleRegion.ReadObject(puckCircleFile);           //读取roi
                else
                {
                    MessageBox.Show("puck circle Region 为空！");
                    return;
                }
                string puckLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line1.hobj";
                if (File.Exists(puckLine1File)) puckLine1Region.ReadObject(puckLine1File);           //读取roi
                else
                {
                    MessageBox.Show("puck line1 Region 为空！");
                    return;
                }
                string puckLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line2.hobj";
                if (File.Exists(puckLine2File)) puckLine2Region.ReadObject(puckLine2File);           //读取roi
                else
                {
                    MessageBox.Show("puck line2 Region 为空！");
                    return;
                }

                string springCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//circle.hobj";
                if (File.Exists(springCircleFile)) springCircleRegion.ReadObject(springCircleFile);           //读取roi
                else
                {
                    MessageBox.Show("spring circle Region 为空！");
                    return;
                }
                string springLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//line1.hobj";
                if (File.Exists(springLine1File)) springLine1Region.ReadObject(springLine1File);           //读取roi
                else
                {
                    MessageBox.Show("spring line1 Region 为空！");
                    return;
                }
                string springLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//line2.hobj";
                if (File.Exists(springLine2File)) springLine2Region.ReadObject(springLine2File);           //读取roi
                else
                {
                    MessageBox.Show("spring line2 Region 为空！");
                    return;
                }
                detectTime.Reset();
                detectTime.Start();
                if (halconAlgorithm.GetReviewPosition(ho_reviewLowImage, ho_reviewHighImage, ProjectInfo.Parameter.reviewLowFitCirclePara,
                    ProjectInfo.Parameter.reviewLowPartLine1Para, ProjectInfo.Parameter.reviewLowPartLine2Para, ProjectInfo.Parameter.reviewHighFitCirclePara, ProjectInfo.Parameter.reviewLowSpringLine1Para, ProjectInfo.Parameter.reviewLowSpringLine2Para,
                    puckCircleRegion, puckLine1Region, puckLine2Region, springCircleRegion, springLine1Region, springLine2Region,
                    ProjectInfo.Parameter.reviewPartOutCircleRadius / ShareData.upCamPixSize1_Y, ProjectInfo.Parameter.reviewSpringOutCircleRadius / ShareData.upCamPixSize1_Y, ProjectInfo.Parameter.reviewSeekCornerStartPhi,
                    ProjectInfo.Parameter.reviewSeekCornerEndPhi, out ho_fitPartCircleContour,
                    out ho_fitSpringCircleContour, out ho_fitPartLine1Contour, out ho_fitPartLine2Contour, out ho_fitSpringLine1Contour, out ho_fitSpringLine2Contour, out ho_fitPartLine, out ho_fitSpringLine,
                    out ho_circleDisLine, out disOfTwoCircle, out Offset_X, out Offset_Y, out offset_Angle, out bugInfo))
                {
                    HOperatorSet.SetColor(hWindowControl4.HalconWindow, "blue");
                    HOperatorSet.SetColor(hWindowControl3.HalconWindow, "blue");
                    HOperatorSet.DispObj(ho_fitPartCircleContour, hWindowControl4.HalconWindow);
                    HOperatorSet.DispObj(ho_fitPartLine1Contour, hWindowControl4.HalconWindow);
                    HOperatorSet.DispObj(ho_fitPartLine2Contour, hWindowControl4.HalconWindow);
                    HOperatorSet.DispObj(ho_fitSpringLine1Contour, hWindowControl3.HalconWindow);
                    HOperatorSet.DispObj(ho_fitSpringLine2Contour, hWindowControl3.HalconWindow);
                    HOperatorSet.DispObj(ho_fitPartLine, hWindowControl4.HalconWindow);
                    HOperatorSet.SetColor(hWindowControl4.HalconWindow, "cyan");
                    HOperatorSet.DispObj(ho_fitSpringLine, hWindowControl4.HalconWindow);
                    HOperatorSet.SetColor(hWindowControl4.HalconWindow, "coral");
                    HOperatorSet.DispObj(ho_circleDisLine, hWindowControl4.HalconWindow);
                    HOperatorSet.DispObj(ho_fitSpringCircleContour, hWindowControl3.HalconWindow);
                    this.tB_disOfTwoCircle.Text = (disOfTwoCircle * ShareData.upCamPixSize1_Y).ToString("f3");
                    this.tB_reveiwAngleOffset.Text = offset_Angle.ToString("f3");
                    this.tB_reviewXOffset.Text = (Offset_X * ShareData.upCamPixSize1_Y).ToString("f3");
                    this.tB_reviewYOffset.Text = (Offset_Y * ShareData.upCamPixSize1_Y).ToString("f3");
                }
                else
                    MessageBox.Show("检测失败！" + bugInfo);
                ho_fitPartCircleContour.Dispose();
                ho_fitSpringCircleContour.Dispose();
                ho_fitPartLine1Contour.Dispose();
                ho_fitPartLine2Contour.Dispose();
                ho_fitSpringLine1Contour.Dispose();
                ho_fitSpringLine2Contour.Dispose();
                ho_fitPartLine.Dispose();
                ho_fitSpringLine.Dispose();
                ho_circleDisLine.Dispose();
                puckCircleRegion.Dispose();
                puckLine1Region.Dispose();
                puckLine2Region.Dispose();
                springCircleRegion.Dispose();
                springLine1Region.Dispose();
                springLine2Region.Dispose();
                detectTime.Stop();
                this.lab_reviewDetectTime.Text = "用时：" + detectTime.ElapsedMilliseconds.ToString() + "ms";
            }
        }
        #endregion

        private void btn_savePara_Click(object sender, EventArgs e)
        {
            try
            {
                ProjectInfo.Parameter.coilReviewLineCornerStartPhi = double.Parse(this.tB_coilReviewCornerStart.Text);
                ProjectInfo.Parameter.coilReviewLineCornerEndPhi = double.Parse(this.tB_coilReviewCornerEnd.Text);
                ProjectInfo.Parameter.coilReviewOutCircleRadius = double.Parse(this.tB_coilReviewOutCircleRadius.Text);

                ProjectInfo.Parameter.tcpIpAddress = this.tB_socketIpAddress.Text;
                ProjectInfo.Parameter.tcpPort = (int)this.socketPort.Value;
                ProjectInfo.Parameter.downCamLocateOutCircleRadius = double.Parse(this.tB_downCamOutCircleRadius.Text);
                ProjectInfo.Parameter.upCamLocateOutCircleRadius = double.Parse(this.tB_upCamOutCircleRadius.Text);
                ProjectInfo.Parameter.reviewPartOutCircleRadius = double.Parse(this.tB_reviewPuckOutCircleRadius.Text);
                ProjectInfo.Parameter.reviewSpringOutCircleRadius = double.Parse(this.tB_reviewSpringOutCircleRadius.Text);
                ProjectInfo.Parameter.maxAngleOffset = double.Parse(this.tB_MaxAngleOffset.Text);
                ProjectInfo.Parameter.maxXOffset = double.Parse(this.tB_MaxXOffset.Text);
                ProjectInfo.Parameter.maxYOffset = double.Parse(this.tB_MaxYOffset.Text);

                ProjectInfo.Parameter.buChang_Angle1 = double.Parse(this.tB_buChangAngle1.Text);
                ProjectInfo.Parameter.buChang_X1 = double.Parse(this.tB_buChangX1.Text);
                ProjectInfo.Parameter.buChang_Y1 = double.Parse(this.tB_buChangY1.Text);


                ProjectInfo.Parameter.buChang_Angle2 = double.Parse(this.tB_buChangAngle2.Text);
                ProjectInfo.Parameter.buChang_X2 = double.Parse(this.tB_buChangX2.Text);
                ProjectInfo.Parameter.buChang_Y2 = double.Parse(this.tB_buChangY2.Text);


                ProjectInfo.Parameter.oKRotateAngle = double.Parse(this.tB_OKRotateAngle.Text);
                ProjectInfo.Parameter.reviewMaxPosOffset = double.Parse(this.btn_reviewMaxPosOffset.Text);
                ProjectInfo.Parameter.reviewMaxAngleOffset = double.Parse(this.btn_reviewMaxAngleOffset.Text);
                ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi = double.Parse(this.tB_upCamSeekStartPhi.Text);
                ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi = double.Parse(this.tB_upCamSeekEndPhi.Text);

                ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi2 = double.Parse(this.tB_upCamSeekStartPhi2.Text);
                ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi2 = double.Parse(this.tB_upCamSeekEndPhi2.Text);
                ProjectInfo.Parameter.upCamLocateOutCircleRadius2 = double.Parse(this.tB_upCamOutCircleRadius2.Text);

                ProjectInfo.Parameter.simoROI1R1 = double.Parse(tB_simoROI1R1.Text);
                ProjectInfo.Parameter.simoROI1C1 = double.Parse(tB_simoROI1C1.Text);
                ProjectInfo.Parameter.simoROI1R2 = double.Parse(tB_simoROI1R2.Text);
                ProjectInfo.Parameter.simoROI1C2 = double.Parse(tB_simoROI1C2.Text);

                ProjectInfo.Parameter.simoROI2R1 = double.Parse(tB_simoROI2R1.Text);
                ProjectInfo.Parameter.simoROI2C1 = double.Parse(tB_simoROI2C1.Text);
                ProjectInfo.Parameter.simoROI2R2 = double.Parse(tB_simoROI2R2.Text);
                ProjectInfo.Parameter.simoROI2C2 = double.Parse(tB_simoROI2C2.Text);


                ProjectInfo.Parameter.downCamLocateSeekCornerStartPhi = double.Parse(this.tB_downCamSeekStartPhi.Text);
                ProjectInfo.Parameter.downCamLocateSeekCornerEndPhi = double.Parse(this.tB_downCamSeekEndPhi.Text);
                ProjectInfo.Parameter.reviewSeekCornerStartPhi = double.Parse(this.tB_reviewSeekStartPhi.Text);
                ProjectInfo.Parameter.reviewSeekCornerEndPhi = double.Parse(this.tB_reviewSeekEndPhi.Text);
                ProjectInfo.Parameter.scannerIpAddress = this.tB_scannerIpAddress.Text;
                ProjectInfo.Parameter.saveImageType = this.cB_saveImageType.SelectedIndex;
                ProjectInfo.Parameter.saveImageFormat = this.cB_saveImageFormat.SelectedIndex;
                ProjectInfo.Parameter.saveImagePath = this.tB_savePath.Text;
                ProjectInfo.Parameter.saveImageDays = (int)this.nUD_saveImageDays.Value;
                if (this.cB_saveDetectImage.Checked)
                    ProjectInfo.Parameter.isSaveDetectImage = true;
                else
                    ProjectInfo.Parameter.isSaveDetectImage = false;
                if (this.cB_isOutputReport.Checked)
                    ProjectInfo.Parameter.isSaveReport = true;
                else
                    ProjectInfo.Parameter.isSaveReport = false;
                ProjectInfo.Parameter.saveReportPath = this.tB_saveReportPath.Text;

                ProjectInfo.Parameter.innerRadius = int.Parse(tbInnerRadius.Text);
                ProjectInfo.Parameter.outerRadius = int.Parse(tbOuterRadius.Text);

                ProjectInfo.SaveParameter(ShareData.configPath); //保存配置文件 

                ProjectInfo.ReadProjectConfig(ShareData.configPath);   //创建配置文件
                MessageBox.Show("保存参数成功！");
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存参数失败！" + ex.Message);
            }
        }
        private void btn_closeForm_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void btn_scanSaveImagePath_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.tB_savePath.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btn_GlueDetection_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.glueDetectPara == null) ProjectInfo.Parameter.glueDetectPara = new BlobDetectPara();
            if (ProjectInfo.Parameter.downCamLocateMatchPara == null) ProjectInfo.Parameter.downCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
            BlobDetect blobDetectForm = new BlobDetect(ProjectInfo.Parameter.glueDetectPara, modelImageFold, ProjectInfo.Parameter.downCamLocateMatchPara);
            blobDetectForm.ShowDialog();
        }

        private void btn_detectSpringGlue_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.springGlueDetectPara == null) ProjectInfo.Parameter.springGlueDetectPara = new FitCirclePara();
            if (ProjectInfo.Parameter.downCamLocateMatchPara == null) ProjectInfo.Parameter.downCamLocateMatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
            MeaRingForm springGlueDetectForm = new MeaRingForm(ProjectInfo.Parameter.springGlueDetectPara, modelImageFold, ProjectInfo.Parameter.downCamLocateMatchPara);
            springGlueDetectForm.ShowDialog();
            ProjectInfo.Parameter.springGlueDetectPara.contrast = springGlueDetectForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.springGlueDetectPara.fitNum = springGlueDetectForm.outFitCirclePara.fitNum;
            ProjectInfo.Parameter.springGlueDetectPara.ho_ROI = springGlueDetectForm.outFitCirclePara.ho_ROI.Clone();
            ProjectInfo.Parameter.springGlueDetectPara.maxGray = springGlueDetectForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.springGlueDetectPara.minGray = springGlueDetectForm.outFitCirclePara.minGray;
            //ProjectInfo.Parameter.springGlueDetectPara.seekPointPath = springGlueDetectForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.springGlueDetectPara.sigma = springGlueDetectForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.springGlueDetectPara.isInheritModel = springGlueDetectForm.outFitCirclePara.isInheritModel;
            ProjectInfo.Parameter.springGlueDetectPara.limitMinRingWidth = springGlueDetectForm.outFitCirclePara.limitMinRingWidth;
            ProjectInfo.Parameter.springGlueDetectPara.limitMaxRingWidth = springGlueDetectForm.outFitCirclePara.limitMaxRingWidth;
        }

        private void groupBox13_Enter(object sender, EventArgs e)
        {

        }

        #region coil 自检参数
        private void btn_coilReview1Modle_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReview1MatchPara == null) ProjectInfo.Parameter.coilReview1MatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "coilReview1");
            MatchForm matchForm = new MatchForm(ProjectInfo.Parameter.coilReview1MatchPara, modelImageFold);
            matchForm.ShowDialog();
            ProjectInfo.Parameter.coilReview1MatchPara.modelLocationCol = matchForm.outMatchPara.modelLocationCol;
            ProjectInfo.Parameter.coilReview1MatchPara.modelLocationRow = matchForm.outMatchPara.modelLocationRow;
            ProjectInfo.Parameter.coilReview1MatchPara.modelMatchType = matchForm.outMatchPara.modelMatchType;
            ProjectInfo.Parameter.coilReview1MatchPara.seekAngleRange = matchForm.outMatchPara.seekAngleRange;
            ProjectInfo.Parameter.coilReview1MatchPara.seekAngleStart = matchForm.outMatchPara.seekAngleStart;
            ProjectInfo.Parameter.coilReview1MatchPara.seekModelNum = matchForm.outMatchPara.seekModelNum;
            ProjectInfo.Parameter.coilReview1MatchPara.seekModelScore = matchForm.outMatchPara.seekModelScore;


        }
        private void btn_coilReview2Modle_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReview2MatchPara == null) ProjectInfo.Parameter.coilReview2MatchPara = new MatchPara();
            string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "coilReview2");
            MatchForm matchForm = new MatchForm(ProjectInfo.Parameter.coilReview2MatchPara, modelImageFold);
            matchForm.ShowDialog();
            ProjectInfo.Parameter.coilReview2MatchPara.modelLocationCol = matchForm.outMatchPara.modelLocationCol;
            ProjectInfo.Parameter.coilReview2MatchPara.modelLocationRow = matchForm.outMatchPara.modelLocationRow;
            ProjectInfo.Parameter.coilReview2MatchPara.modelMatchType = matchForm.outMatchPara.modelMatchType;
            ProjectInfo.Parameter.coilReview2MatchPara.seekAngleRange = matchForm.outMatchPara.seekAngleRange;
            ProjectInfo.Parameter.coilReview2MatchPara.seekAngleStart = matchForm.outMatchPara.seekAngleStart;
            ProjectInfo.Parameter.coilReview2MatchPara.seekModelNum = matchForm.outMatchPara.seekModelNum;
            ProjectInfo.Parameter.coilReview2MatchPara.seekModelScore = matchForm.outMatchPara.seekModelScore;

        }
        private void btn_setCoilReviewCircle1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReviewFitCircle1 == null) ProjectInfo.Parameter.coilReviewFitCircle1 = new FitCirclePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//circle.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi

            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.coilReviewFitCircle1, hv_region);
            fitCircleForm.SetBlobLocate(20, 55, 34, 66);      //设置blob定位

            fitCircleForm.ShowDialog();
            fitCircleForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.coilReviewFitCircle1.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.coilReviewFitCircle1.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.coilReviewFitCircle1.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI;
            ProjectInfo.Parameter.coilReviewFitCircle1.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.coilReviewFitCircle1.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.coilReviewFitCircle1.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.coilReviewFitCircle1.sigma = fitCircleForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.coilReviewFitCircle1.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;//+++++++++
            hv_region.Dispose();
        }

        private void btn_setCoilReviewCircle2_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReviewFitCircle2 == null) ProjectInfo.Parameter.coilReviewFitCircle2 = new FitCirclePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//circle.hobj";   //二次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.coilReviewFitCircle2, hv_region);
            fitCircleForm.ShowDialog();
            fitCircleForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.coilReviewFitCircle2.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.coilReviewFitCircle2.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.coilReviewFitCircle2.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI;
            ProjectInfo.Parameter.coilReviewFitCircle2.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.coilReviewFitCircle2.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.coilReviewFitCircle2.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.coilReviewFitCircle2.sigma = fitCircleForm.outFitCirclePara.sigma;

            ProjectInfo.Parameter.coilReviewFitCircle2.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;//+++++++++
            hv_region.Dispose();
        }

        private void btn_setCoilReviewSRLine1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReviewFitSRLine1 == null) ProjectInfo.Parameter.coilReviewFitSRLine1 = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line1.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.coilReviewFitSRLine1, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.coilReviewFitSRLine1.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.coilReviewFitSRLine1.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.coilReviewFitSRLine1.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.coilReviewFitSRLine1.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.coilReviewFitSRLine1.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.coilReviewFitSRLine1.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.coilReviewFitSRLine1.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.coilReviewFitSRLine1.sigma = fitLineForm.outFitLinePara.sigma;
            hv_region.Dispose();
        }

        private void btn_setCoilReviewSRLine2_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReviewFitSRLine2 == null) ProjectInfo.Parameter.coilReviewFitSRLine2 = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line2.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.coilReviewFitSRLine2, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.coilReviewFitSRLine2.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.coilReviewFitSRLine2.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.coilReviewFitSRLine2.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.coilReviewFitSRLine2.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.coilReviewFitSRLine2.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.coilReviewFitSRLine2.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.coilReviewFitSRLine2.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.coilReviewFitSRLine2.sigma = fitLineForm.outFitLinePara.sigma;
            hv_region.Dispose();
        }

        private void btn_setCoilReview3Line1_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReviewFitLine3 == null) ProjectInfo.Parameter.coilReviewFitLine3 = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review3") + "//line1.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.coilReviewFitLine3, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.coilReviewFitLine3.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.coilReviewFitLine3.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.coilReviewFitLine3.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.coilReviewFitLine3.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.coilReviewFitLine3.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.coilReviewFitLine3.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.coilReviewFitLine3.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.coilReviewFitLine3.sigma = fitLineForm.outFitLinePara.sigma;

            ProjectInfo.Parameter.coilReviewFitLine3.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;//+++++++++
            hv_region.Dispose();
        }

        private void btn_setCoilReviewCircle4_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.coilReviewFitLine4 == null) ProjectInfo.Parameter.coilReviewFitLine4 = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review3") + "//line2.hobj";   //一次曝光
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.coilReviewFitLine4, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.coilReviewFitLine4.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.coilReviewFitLine4.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.coilReviewFitLine4.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.coilReviewFitLine4.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.coilReviewFitLine4.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.coilReviewFitLine4.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.coilReviewFitLine4.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.coilReviewFitLine4.sigma = fitLineForm.outFitLinePara.sigma;
            hv_region.Dispose();
        }
        private void LoadCoilMatchModel(out HTuple hv_matchModel)
        {
            hv_matchModel = null;
            try
            {
                string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "coilReview1");
                if (ProjectInfo.Parameter.coilReview1MatchPara.modelMatchType == 0)   //基于形状
                {
                    string shapeModelFile = modelImageFold + "\\model.shm";
                    if (!File.Exists(shapeModelFile))
                    {
                        MessageBox.Show("模板文件不存在，请先加载模型！");
                        return;
                    }
                    HOperatorSet.ReadShapeModel(shapeModelFile, out hv_matchModel);  //加载模板
                }
                else if (ProjectInfo.Parameter.coilReview1MatchPara.modelMatchType == 1)  //基于灰度
                {
                    string nccModelFile = modelImageFold + "\\model.ncm";
                    if (!File.Exists(nccModelFile))
                    {
                        MessageBox.Show("模板文件不存在，请先加载模型！");
                        return;
                    }
                    HOperatorSet.ReadNccModel(nccModelFile, out hv_matchModel);  //加载模板
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void btn_detectCoilReviewImg1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //this.tB_upCamImagePath.Text = openFileDialog.FileName;
                HObject ho_Image = null;
                HObject ho_fitCircleContour = null;
                HObject ho_fitLine1Contour = null;
                HObject ho_fitLine2Contour = null;
                HObject ho_fitAngleLine = null;
                HTuple hv_ImageWidth, hv_ImageHeight = null;
                HOperatorSet.GenEmptyObj(out ho_Image);
                ho_Image.Dispose();
                HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);

                HObject review1_circle = null;
                HObject review1_line1 = null;
                HObject review1_line2 = null;
                HOperatorSet.GenEmptyObj(out review1_circle);
                HOperatorSet.GenEmptyObj(out review1_line1);
                HOperatorSet.GenEmptyObj(out review1_line2);
                string upCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//circle.hobj";
                if (File.Exists(upCircleFile)) review1_circle.ReadObject(upCircleFile);           //读取roi
                else
                {
                    MessageBox.Show("上相机circleRegion为空！");
                    return;
                }
                string upLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line1.hobj";
                if (File.Exists(upLine1File)) review1_line1.ReadObject(upLine1File);            //读取roi
                else
                {
                    MessageBox.Show("上相机line1Region为空！");
                    return;
                }
                string upLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "review1") + "//line2.hobj";
                if (File.Exists(upLine2File)) review1_line2.ReadObject(upLine2File);            //读取roi
                else
                {
                    MessageBox.Show("上相机line2Region为空！");
                    return;
                }
                double angle = 0;
                string bugInfo = "";
                int countROI = 0;
                //HTuple hv_matchModel = null;
                //LoadCoilMatchModel(out hv_matchModel);
                //if (hv_matchModel == null) return;
                detectTime.Reset();
                detectTime.Start();
                halconAlgorithm.GetCoilPuckLocateROI(ho_Image, out review1_circle);
                //if (countROI < 1)//增加方法2blob
                //    halconAlgorithm.GetCoilPuckLocateROI2(ho_Image, out review1_circle, 34, 66, out countROI);
                if (halconAlgorithm.GetPuckPosition(ho_Image, ProjectInfo.Parameter.coilReviewFitCircle1,
                    ProjectInfo.Parameter.coilReviewFitSRLine1, ProjectInfo.Parameter.coilReviewFitSRLine2, review1_circle, review1_line1, review1_line2, ProjectInfo.Parameter.coilReviewOutCircleRadius / ShareData.reviewPixSize_Y,
                    ProjectInfo.Parameter.coilReviewLineCornerStartPhi, ProjectInfo.Parameter.coilReviewLineCornerEndPhi,
                    out ho_fitCircleContour, out ho_fitLine1Contour, out ho_fitLine2Contour,
                    out ho_fitAngleLine, out coilReviewFitCircle1_X, out coilReviewFitCircle1_Y, out coidReviewLineCorner_X, out coidReviewLineCorner_Y, out angle, out bugInfo))
                {
                    halconAlgorithm.ho_AdaptiveImage(hWindowControl_coilReview1, hv_ImageWidth, hv_ImageHeight);
                    hWindowControl_coilReview1.HalconWindow.ClearWindow();
                    HOperatorSet.DispObj(ho_Image, hWindowControl_coilReview1.HalconWindow);
                    HOperatorSet.SetColor(hWindowControl_coilReview1.HalconWindow, "blue");
                    HOperatorSet.DispObj(ho_fitAngleLine, hWindowControl_coilReview1.HalconWindow);
                    HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl_coilReview1.HalconWindow);
                    HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl_coilReview1.HalconWindow);
                    HOperatorSet.DispObj(ho_fitLine2Contour, hWindowControl_coilReview1.HalconWindow);
                }
                else
                {
                    MessageBox.Show("检测失败！" + bugInfo);
                }
                ho_Image.Dispose();
                ho_fitAngleLine.Dispose();
                ho_fitCircleContour.Dispose();
                ho_fitLine1Contour.Dispose();
                ho_fitLine2Contour.Dispose();
                detectTime.Stop();
                //this.tB_upCamDetectTime.Text = detectTime.ElapsedMilliseconds.ToString();
            }
        }

        private void btn_detectCoilReviewImg2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //this.tB_upCamImagePath.Text = openFileDialog.FileName;
                try
                {
                    HObject ho_Image = null;
                    HObject ho_fitCircleContour = null;
                    HTuple hv_circle_Radius = null;
                    HTuple hv_ImageWidth, hv_ImageHeight = null;
                    HTuple coilReviewFitCircle2_row = null;
                    HTuple coilReviewFitCircle2_col = null;
                    HOperatorSet.GenEmptyObj(out ho_Image);
                    ho_Image.Dispose();
                    HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                    HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                    HOperatorSet.GenEmptyObj(out ho_fitCircleContour);
                    ho_fitCircleContour.Dispose();
                    if (true)
                    {
                        HObject hv_cross = null;
                        HOperatorSet.GenEmptyObj(out hv_cross);
                        hv_cross.Dispose();
                        HTuple hv_result = null;
                        //halconAlgorithm.Fit8PointsCircle_coil(ho_Image, out hv_cross, coilReviewFitCircle1_Y, coilReviewFitCircle1_X, 1579, coidReviewLineCorner_Y, coidReviewLineCorner_X, 
                        //    out coilReviewFitCircle2_row, out coilReviewFitCircle2_col, out hv_circle_Radius, out hv_result);
                        if (hv_result == 1)
                        {
                            MessageBox.Show("交点提取失败!");
                            return;
                        }
                        else
                        {
                            HOperatorSet.GenCircle(out ho_fitCircleContour, coilReviewFitCircle2_row, coilReviewFitCircle2_col, hv_circle_Radius);
                        }
                        hv_cross.Dispose();
                    }
                    else
                    {

                        HObject review2ROI_circle = null;
                        HOperatorSet.GenEmptyObj(out review2ROI_circle);
                        string review2CircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "review2") + "//circle.hobj";
                        if (File.Exists(review2CircleFile)) review2ROI_circle.ReadObject(review2CircleFile);           //读取roi
                        else
                        {
                            MessageBox.Show("自检2相机circleRegion为空！");
                            return;
                        }
                        HTuple hv_circlePara = new HTuple();
                        hv_circlePara[0] = ProjectInfo.Parameter.coilReviewFitCircle2.minGray;
                        hv_circlePara[1] = ProjectInfo.Parameter.coilReviewFitCircle2.maxGray;
                        hv_circlePara[2] = ProjectInfo.Parameter.coilReviewFitCircle2.contrast;
                        hv_circlePara[3] = ProjectInfo.Parameter.coilReviewFitCircle2.fitNum;
                        hv_circlePara[4] = ProjectInfo.Parameter.coilReviewFitCircle2.sigma;
                        hv_circlePara[5] = ProjectInfo.Parameter.coilReviewFitCircle2.seekPointPath;
                        ho_fitCircleContour.Dispose();
                        halconAlgorithm.FittingCircle(ho_Image, review2ROI_circle, out ho_fitCircleContour, hv_circlePara, out coilReviewFitCircle2_row, out coilReviewFitCircle2_col, out hv_circle_Radius);
                        review2ROI_circle.Dispose();
                    }
                    if (hv_circle_Radius > 0)
                    {
                        halconAlgorithm.ho_AdaptiveImage(hWindowControl_coilReview2, hv_ImageWidth, hv_ImageHeight);
                        hWindowControl_coilReview2.HalconWindow.ClearWindow();
                        HOperatorSet.DispObj(ho_Image, hWindowControl_coilReview2.HalconWindow);
                        HOperatorSet.SetColor(hWindowControl_coilReview2.HalconWindow, "blue");
                        HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl_coilReview2.HalconWindow);
                        coilReviewFitCircle2_X = coilReviewFitCircle2_col.D;
                        coilReviewFitCircle2_Y = coilReviewFitCircle2_row.D;
                    }
                    else
                    {
                        MessageBox.Show("圆拟合失败");
                    }
                    ho_fitCircleContour.Dispose();

                    ho_Image.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
        }

        private void btn_detectCoilReviewImg3_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    HObject ho_Image = null;
                    HObject ho_lineContour = null;
                    HTuple hv_circle_Radius = null;
                    HTuple hv_ImageWidth, hv_ImageHeight = null;
                    HOperatorSet.GenEmptyObj(out ho_Image);
                    ho_Image.Dispose();
                    HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                    HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                    HOperatorSet.GenEmptyObj(out ho_lineContour);
                    HObject review3ROI_line1 = null;
                    HOperatorSet.GenEmptyObj(out review3ROI_line1);
                    string review3line1File = Path.Combine(System.Environment.CurrentDirectory, "region", "review3") + "//line1.hobj";
                    if (File.Exists(review3line1File)) review3ROI_line1.ReadObject(review3line1File);           //读取roi
                    else
                    {
                        MessageBox.Show("自检2相机circleRegion为空！");
                        return;
                    }
                    HTuple hv_Line1Para = new HTuple();
                    hv_Line1Para[0] = ProjectInfo.Parameter.coilReviewFitLine3.sigma;
                    hv_Line1Para[1] = ProjectInfo.Parameter.coilReviewFitLine3.contrast;
                    switch (ProjectInfo.Parameter.coilReviewFitLine3.grayTransition)
                    {
                        case 0:
                            hv_Line1Para[2] = "all";
                            break;
                        case 1:
                            hv_Line1Para[2] = "positive";
                            break;
                        case 2:
                            hv_Line1Para[2] = "negative";
                            break;
                    }
                    switch (ProjectInfo.Parameter.coilReviewFitLine3.pointPosition)
                    {
                        case 0:
                            hv_Line1Para[3] = "all";
                            break;
                        case 1:
                            hv_Line1Para[3] = "first";
                            break;
                        case 2:
                            hv_Line1Para[3] = "last";
                            break;
                    }
                    hv_Line1Para[4] = ProjectInfo.Parameter.coilReviewFitLine3.fitNum;
                    ho_lineContour.Dispose();
                    HTuple hv_RowBegin = new HTuple(), hv_ColBegin = new HTuple();
                    HTuple hv_RowEnd = new HTuple(), hv_ColEnd = new HTuple();
                    halconAlgorithm.FittingLine(ho_Image, review3ROI_line1, out ho_lineContour, hv_Line1Para, ProjectInfo.Parameter.coilReviewFitLine3.LSJudge, ProjectInfo.Parameter.coilReviewFitLine3.LSAngle,
                            out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd);
                    if (true)
                    {
                        HObject hv_cornerCross = null;
                        HOperatorSet.GenEmptyObj(out hv_cornerCross);
                        hv_cornerCross.Dispose();
                        halconAlgorithm.FitCoilLine(ho_Image, out hv_cornerCross, coilReviewFitCircle1_Y, coilReviewFitCircle1_X, coidReviewLineCorner_Y, coidReviewLineCorner_X, hv_RowBegin.Clone(), hv_ColBegin.Clone(), hv_RowEnd.Clone(), hv_ColEnd.Clone(), 3 / ShareData.reviewPixSize_Y,
                            out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd);
                    }
                    if (hv_RowBegin > 0)
                    {
                        halconAlgorithm.ho_AdaptiveImage(hWindowControl_coilReview3, hv_ImageWidth, hv_ImageHeight);
                        hWindowControl_coilReview3.HalconWindow.ClearWindow();
                        HOperatorSet.DispObj(ho_Image, hWindowControl_coilReview3.HalconWindow);
                        HOperatorSet.SetColor(hWindowControl_coilReview3.HalconWindow, "blue");
                        HOperatorSet.DispObj(ho_lineContour, hWindowControl_coilReview3.HalconWindow);
                        coilReviewFitLineS_X = hv_ColBegin.D;
                        coilReviewFitLineS_Y = hv_RowBegin.D;
                        coilReviewFitLineE_X = hv_ColEnd.D;
                        coilReviewFitLineE_Y = hv_RowEnd.D;
                    }
                    else
                    {
                        MessageBox.Show("拟合线1失败");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        #endregion
        private void btn_confirmPassword_Click(object sender, EventArgs e)
        {
            CINIFactory systemPara = new CINIFactory(System.Environment.CurrentDirectory + "\\", "item");
            string originalPassword = systemPara.ReadIniData("password", "password", "");
            if (this.tB_originalPassword.Text == originalPassword)
            {
                if (this.tB_newPassword.Text != "")
                {
                    systemPara.WriteIniData("password", "password", this.tB_newPassword.Text);
                    ShareData.loginPassword = this.tB_newPassword.Text;
                    MessageBox.Show("新密码设置成功！");
                }
                else
                    MessageBox.Show("新密码不能为空！");
            }
            else
            {
                MessageBox.Show("原密码输入错误！");
            }
        }

        private void btn_springAccuracy_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //this.tB_savePath.Text = folderBrowserDialog1.SelectedPath;                
                string selectPath = folderBrowserDialog1.SelectedPath;
                string dataPath = selectPath + "\\data.csv";
                StreamWriter swite = new StreamWriter(dataPath, true);
                HObject ho_Image = null;
                // Local control variables 
                HTuple hv_ImageFiles = new HTuple(), hv_Index = new HTuple();
                // Initialize local and output iconic variables 
                HOperatorSet.GenEmptyObj(out ho_Image);
                //Image Acquisition 01: Code generated by Image Acquisition 01
                hv_ImageFiles.Dispose();
                HOperatorSet.ListFiles(selectPath, (new HTuple("files")).TupleConcat(
                    "follow_links"), out hv_ImageFiles);
                {
                    HTuple ExpTmpOutVar_0;
                    HOperatorSet.TupleRegexpSelect(hv_ImageFiles, (new HTuple("\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$")).TupleConcat(
                        "ignore_case"), out ExpTmpOutVar_0);
                    hv_ImageFiles.Dispose();
                    hv_ImageFiles = ExpTmpOutVar_0;
                }
                for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_ImageFiles.TupleLength()
                    )) - 1); hv_Index = (int)hv_Index + 1)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Image.Dispose();
                        HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_Index));
                        HObject ho_fitCircleContour = null;
                        HObject ho_fitLine1Contour = null;
                        HTuple hv_ImageWidth, hv_ImageHeight = null;
                        HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                        double circle_X = 0;
                        double circle_Y = 0;
                        double angle = 0;
                        string bugInfo = "";
                        HTuple hv_matchModel = null;
                        string modelImageFold = Path.Combine(System.Environment.CurrentDirectory, "model", "downCamLocate");
                        if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 0)   //基于形状
                        {
                            string shapeModelFile = modelImageFold + "\\model.shm";
                            if (!File.Exists(shapeModelFile))
                            {
                                MessageBox.Show("模板文件不存在，请先加载模型！");
                                return;
                            }
                            HOperatorSet.ReadShapeModel(shapeModelFile, out hv_matchModel);  //加载模板
                        }
                        else if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 1)  //基于灰度
                        {
                            string nccModelFile = modelImageFold + "\\model.ncm";
                            if (!File.Exists(nccModelFile))
                            {
                                MessageBox.Show("模板文件不存在，请先加载模型！");
                                return;
                            }
                            HOperatorSet.ReadNccModel(nccModelFile, out hv_matchModel);  //加载模板
                        }
                        HObject downCamROI_circle = null;
                        HObject downCamROI_line1 = null;
                        HObject downCamROI_line2 = null;
                        HOperatorSet.GenEmptyObj(out downCamROI_circle);
                        HOperatorSet.GenEmptyObj(out downCamROI_line1);
                        HOperatorSet.GenEmptyObj(out downCamROI_line2);
                        string downCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//circle.hobj";
                        if (File.Exists(downCircleFile)) downCamROI_circle.ReadObject(downCircleFile);           //读取roi
                        else
                        {
                            MessageBox.Show("下相机circleRegion为空！");
                            return;
                        }
                        string downLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//line1.hobj";
                        if (File.Exists(downLine1File)) downCamROI_line1.ReadObject(downLine1File);           //读取roi
                        else
                        {
                            MessageBox.Show("下相机line1Region为空！");
                            return;
                        }
                        detectTime.Reset();
                        detectTime.Start();
                        if (ShareData.projectItem == ShareData.ItemType.自动线coil组装 || ShareData.projectItem == ShareData.ItemType.coil半自动线)
                        {
                            if (halconAlgorithm.GetCoilPosition_match(ho_Image, hv_matchModel, ProjectInfo.Parameter.downCamLocateMatchPara, ProjectInfo.Parameter.downCamLocateFitCirclePara,
                                        ProjectInfo.Parameter.downCamLocateFitLine1Para, downCamROI_circle, downCamROI_line1, out ho_fitCircleContour, out ho_fitLine1Contour, out circle_X, out circle_Y, out angle, out bugInfo))
                            {
                                halconAlgorithm.ho_AdaptiveImage(hWindowControl2, hv_ImageWidth, hv_ImageHeight);
                                hWindowControl2.HalconWindow.ClearWindow();
                                HOperatorSet.DispObj(ho_Image, hWindowControl2.HalconWindow);
                                HOperatorSet.SetColor(hWindowControl2.HalconWindow, "blue");
                                HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl2.HalconWindow);
                                HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl2.HalconWindow);
                                this.tB_downLocatePoint_X.Text = circle_X.ToString("f2");
                                this.tB_downLocatePoint_Y.Text = circle_Y.ToString("f2");
                                this.tB_downLocateAngle.Text = angle.ToString("f2");
                                swite.Write(circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3"));
                                swite.WriteLine();
                            }
                            else
                            {
                                MessageBox.Show(bugInfo);
                            }
                        }
                        else
                        {
                            //spring
                            string downLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "downCam") + "//line2.hobj";
                            if (File.Exists(downLine2File)) downCamROI_line2.ReadObject(downLine2File);           //读取roi
                            else
                            {
                                MessageBox.Show("下相机line2Region为空！");
                                return;
                            }
                            HObject ho_fitAngleLine = null;
                            HObject ho_fitLine2Contour = null;
                            if (halconAlgorithm.GetSpringPosition_match(ho_Image, hv_matchModel, ProjectInfo.Parameter.downCamLocateMatchPara, ProjectInfo.Parameter.downCamLocateFitCirclePara,
                                    ProjectInfo.Parameter.downCamLocateFitLine1Para, ProjectInfo.Parameter.downCamLocateFitLine2Para, downCamROI_circle, downCamROI_line1, downCamROI_line2, ProjectInfo.Parameter.downCamLocateOutCircleRadius / ShareData.downCamPixSize_X,
                                    ProjectInfo.Parameter.downCamLocateSeekCornerStartPhi, ProjectInfo.Parameter.downCamLocateSeekCornerEndPhi,
                                    out ho_fitCircleContour, out ho_fitLine1Contour, out ho_fitLine2Contour,
                                    out ho_fitAngleLine, out circle_X, out circle_Y, out angle, out bugInfo))
                            {
                                halconAlgorithm.ho_AdaptiveImage(hWindowControl2, hv_ImageWidth, hv_ImageHeight);
                                hWindowControl2.HalconWindow.ClearWindow();
                                HOperatorSet.DispObj(ho_Image, hWindowControl2.HalconWindow);
                                HOperatorSet.SetColor(hWindowControl2.HalconWindow, "blue");
                                HOperatorSet.DispObj(ho_fitAngleLine, hWindowControl2.HalconWindow);
                                HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl2.HalconWindow);
                                HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl2.HalconWindow);
                                HOperatorSet.DispObj(ho_fitLine2Contour, hWindowControl2.HalconWindow);
                                this.tB_downLocatePoint_X.Text = circle_X.ToString("f2");
                                this.tB_downLocatePoint_Y.Text = circle_Y.ToString("f2");
                                this.tB_downLocateAngle.Text = angle.ToString("f2");
                                swite.Write(circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3"));
                                swite.WriteLine();

                                string str = hv_ImageFiles.TupleSelect(hv_Index) + "," + circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3");
                                FileOperate.WriteCSV(2, str);

                            }
                            else
                            {
                                MessageBox.Show(bugInfo);
                            }
                            ho_fitAngleLine.Dispose();
                            ho_fitLine2Contour.Dispose();
                        }
                        ho_fitCircleContour.Dispose();
                        ho_fitLine1Contour.Dispose();
                        detectTime.Stop();
                        this.tB_downCamDetectTime.Text = detectTime.ElapsedMilliseconds.ToString();
                        if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 0)   //基于形状
                        {
                            HOperatorSet.ClearShapeModel(hv_matchModel);                     //清除模板
                        }
                        else if (ProjectInfo.Parameter.downCamLocateMatchPara.modelMatchType == 1)  //基于灰度
                        {
                            HOperatorSet.ClearNccModel(hv_matchModel);                   //清除模板
                        }
                    }
                    //Image Acquisition 01: Do something                 
                }
                swite.Flush();
                swite.Close();
                ho_Image.Dispose();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            double disOfTwoCircle = 0;
            HObject ho_circleDisLine = null;
            double offset_Angle = 0;
            double Offset_X = 0;
            double Offset_Y = 0;
            string bugInfo = "";
            if (halconAlgorithm.GetCoilReviewPosition(coilReviewFitCircle1_X, coilReviewFitCircle1_Y, coidReviewLineCorner_X, coidReviewLineCorner_Y, coilReviewFitCircle2_X, coilReviewFitCircle2_Y,
            coilReviewFitLineS_X, coilReviewFitLineS_Y, coilReviewFitLineE_X, coilReviewFitLineE_Y, out disOfTwoCircle, out ho_circleDisLine,
            out offset_Angle, out Offset_X, out Offset_Y, out bugInfo))
            {
                this.tB_coilccDistance.Text = (disOfTwoCircle * ShareData.reviewPixSize_Y).ToString("f4");
                this.tB_coilAngleOffset.Text = offset_Angle.ToString("f4");
                this.lab_coilOffset_X.Text = (Offset_X * ShareData.reviewPixSize_Y).ToString("f4");
                this.lab_coilOffset_Y.Text = (Offset_Y * ShareData.reviewPixSize_Y).ToString("f4");
                HOperatorSet.SetColor(hWindowControl_coilReview2.HalconWindow, "red");
                HOperatorSet.DispObj(ho_circleDisLine, hWindowControl_coilReview2.HalconWindow);
            }
            else
                MessageBox.Show(bugInfo);
        }

        private void btn_scanSaveReportPath_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.tB_saveReportPath.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btn_offTestGuideImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                HObject ho_Image = null;
                HObject ho_circleContour = null;
                HObject ho_Cross = null;
                HObject ho_ROI = null;
                try
                {
                    HTuple hv_coor_Row = null;
                    HTuple hv_coor_Col = null;
                    HTuple hv_ImageWidth, hv_ImageHeight = null;
                    HTuple hv_cfgPara = new HTuple(250, 255, 50, 200, 1, 1, 1040,940);//最小灰度，最大灰度，对比度，拟合点数量，sigma，从内向外0，ROI外圆半径，ROI内圆半径
                    HOperatorSet.GenEmptyObj(out ho_Image);
                    HOperatorSet.GenEmptyObj(out ho_circleContour);
                    HOperatorSet.GenEmptyObj(out ho_Cross);
                    HOperatorSet.GenEmptyObj(out ho_ROI);
                    ho_Image.Dispose();
                    HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                    HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                    ho_circleContour.Dispose();
                    ho_ROI.Dispose();
                    halconAlgorithm.GetGuideMoveCoorFit(ho_Image, out ho_circleContour, out ho_ROI, hv_cfgPara, out hv_coor_Row, out hv_coor_Col);
                    //halconAlgorithm.GetGuideMoveCoor(ho_Image, out ho_circleContour, out hv_coor_Row, out hv_coor_Col);
                    if (hv_coor_Row > 0)
                    {
                        this.tB_guideCircle_X.Text = hv_coor_Col.D.ToString();
                        this.tB_guideCircle_Y.Text = hv_coor_Row.D.ToString();
                        halconAlgorithm.ho_AdaptiveImage(hWindowControl5, hv_ImageWidth, hv_ImageHeight);
                        hWindowControl5.HalconWindow.ClearWindow();
                        HOperatorSet.DispObj(ho_Image, hWindowControl5.HalconWindow);
                        HOperatorSet.SetColor(hWindowControl5.HalconWindow, "blue");
                        HOperatorSet.DispObj(ho_circleContour, hWindowControl5.HalconWindow);
                        ho_Cross.Dispose();
                        HOperatorSet.GenCrossContourXld(out ho_Cross, hv_coor_Row, hv_coor_Col, 100, 0.785398);
                        HOperatorSet.SetColor(hWindowControl5.HalconWindow, "red");
                        HOperatorSet.DispObj(ho_Cross, hWindowControl5.HalconWindow);
                        HOperatorSet.SetColor(hWindowControl5.HalconWindow, "yellow");
                        HOperatorSet.DispObj(ho_ROI, hWindowControl5.HalconWindow);
                    }
                    else
                    {
                        MessageBox.Show("没法发现产品");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    ho_Cross.Dispose();
                    ho_Image.Dispose();
                    ho_circleContour.Dispose();
                }
            }
        }

        private void btn_SetGuideFitCircle_Click(object sender, EventArgs e)
        {

        }

        private void btn_testUpFolderImage_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                halconAlgorithm.innerRadius = ProjectInfo.Parameter.innerRadius;
                halconAlgorithm.outerRadius = ProjectInfo.Parameter.outerRadius;

                //this.tB_savePath.Text = folderBrowserDialog1.SelectedPath;                
                string selectPath = folderBrowserDialog1.SelectedPath;
                string dataPath = selectPath + "\\data.csv";
                StreamWriter swite = new StreamWriter(dataPath, true);
                HObject ho_Image = null;
                // Local control variables 
                HTuple hv_ImageFiles = new HTuple(), hv_Index = new HTuple();
                // Initialize local and output iconic variables 
                HOperatorSet.GenEmptyObj(out ho_Image);
                //Image Acquisition 01: Code generated by Image Acquisition 01
                hv_ImageFiles.Dispose();
                HOperatorSet.ListFiles(selectPath, (new HTuple("files")).TupleConcat(
                    "follow_links"), out hv_ImageFiles);
                {
                    HTuple ExpTmpOutVar_0;
                    HOperatorSet.TupleRegexpSelect(hv_ImageFiles, (new HTuple("\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$")).TupleConcat(
                        "ignore_case"), out ExpTmpOutVar_0);
                    hv_ImageFiles.Dispose();
                    hv_ImageFiles = ExpTmpOutVar_0;
                }
                for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_ImageFiles.TupleLength()
                    )) - 1); hv_Index = (int)hv_Index + 1)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Image.Dispose();
                        HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_Index));
                        HObject ho_fitCircleContour = null;
                        HObject ho_fitLine1Contour = null;
                        HObject ho_fitLine2Contour = null;
                        HObject ho_fitAngleLine = null;
                        HTuple hv_ImageWidth, hv_ImageHeight = null;
                        HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                        double circle_X = 0;
                        double circle_Y = 0;
                        double lineCorner_X = 0;
                        double lineCorner_Y = 0;
                        double angle = 0;
                        string bugInfo = "";
                        //int countROI = 0;
                        HObject upCamROI_circle = null;
                        HObject upCamROI_line1 = null;
                        HObject upCamROI_line2 = null;
                        HOperatorSet.GenEmptyObj(out upCamROI_circle);
                        HOperatorSet.GenEmptyObj(out upCamROI_line1);
                        HOperatorSet.GenEmptyObj(out upCamROI_line2);
                        string upCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//circle.hobj";
                        if (File.Exists(upCircleFile)) upCamROI_circle.ReadObject(upCircleFile);           //读取roi
                        else
                        {
                            MessageBox.Show("上相机circleRegion为空！");
                            return;
                        }
                        string upLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//line1.hobj";
                        if (File.Exists(upLine1File)) upCamROI_line1.ReadObject(upLine1File);            //读取roi
                        else
                        {
                            MessageBox.Show("上相机line1Region为空！");
                            return;
                        }

                        string upLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam") + "//line2.hobj";
                        if (File.Exists(upLine2File)) upCamROI_line2.ReadObject(upLine2File);            //读取roi
                        else
                        {
                            MessageBox.Show("上相机line2Region为空！");
                            return;
                        }
                        double outCircleRadius = 0;

                        outCircleRadius = ProjectInfo.Parameter.upCamLocateOutCircleRadius / ShareData.upCamPixSize1_Y;      //流道1

                        detectTime.Reset();
                        detectTime.Start();

                        halconAlgorithm.GetCoilPuckLocateROI(ho_Image, out upCamROI_circle);
                        if (halconAlgorithm.GetPuckPosition(ho_Image, ProjectInfo.Parameter.upCamLocateFitCirclePara,
                            ProjectInfo.Parameter.upCamLocateFitLine1Para, ProjectInfo.Parameter.upCamLocateFitLine2Para,
                            upCamROI_circle, upCamROI_line1, upCamROI_line2, ProjectInfo.Parameter.upCamLocateOutCircleRadius / ShareData.upCamPixSize1,
                            ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi, ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi,
                            out ho_fitCircleContour, out ho_fitLine1Contour, out ho_fitLine2Contour,
                            out ho_fitAngleLine, out circle_X, out circle_Y, out lineCorner_X, out lineCorner_Y, out angle, out bugInfo))
                        {
                            halconAlgorithm.ho_AdaptiveImage(hWindowControl1, hv_ImageWidth, hv_ImageHeight);
                            hWindowControl1.HalconWindow.ClearWindow();
                            HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
                            HOperatorSet.SetColor(hWindowControl1.HalconWindow, "blue");
                            HOperatorSet.DispObj(ho_fitAngleLine, hWindowControl1.HalconWindow);
                            HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl1.HalconWindow);
                            HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl1.HalconWindow);
                            HOperatorSet.DispObj(ho_fitLine2Contour, hWindowControl1.HalconWindow);
                            this.tB_upLocatePoint_X.Text = circle_X.ToString("f2");
                            this.tB_upLocatePoint_Y.Text = circle_Y.ToString("f2");
                            this.tB_upLocateAngle.Text = angle.ToString("f2");

                            swite.Write(circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3"));
                            swite.WriteLine();
                        }
                        else
                        {
                            MessageBox.Show("检测失败！" + bugInfo);
                        }
                        ho_Image.Dispose();
                        ho_fitAngleLine.Dispose();
                        ho_fitCircleContour.Dispose();
                        ho_fitLine1Contour.Dispose();
                        ho_fitLine2Contour.Dispose();
                        detectTime.Stop();
                        this.tB_upCamDetectTime.Text = detectTime.ElapsedMilliseconds.ToString();

                        string str = hv_ImageFiles.TupleSelect(hv_Index) + "," + circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3");
                        FileOperate.WriteCSV(1, str);
                    }
                    //Image Acquisition 01: Do something
                }
                swite.Flush();
                swite.Close();
                ho_Image.Dispose();
            }
        }

        private void btn_diTestGuideImage_Click(object sender, EventArgs e)
        {
            string dirPath = "";
            HObject ho_image = null;
            HOperatorSet.GenEmptyObj(out ho_image);

            FolderBrowserDialog opg = new FolderBrowserDialog();

            if (opg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                dirPath = opg.SelectedPath;
            }

            if (dirPath != "")
            {
                string[] fileNames = Directory.GetFiles(dirPath);

                if (fileNames.Length > 0)
                {
                    for (int index = 0; index < fileNames.Length; index++)
                    {
                        HObject ho_Image = null;
                        HObject ho_circleContour = null;
                        HObject ho_Cross = null;
                        HObject ho_ROI = null;
                        try
                        {
                            HTuple hv_coor_Row = null;
                            HTuple hv_coor_Col = null;
                            HTuple hv_ImageWidth, hv_ImageHeight = null;
                            HOperatorSet.GenEmptyObj(out ho_Image);
                            HOperatorSet.GenEmptyObj(out ho_circleContour);
                            HOperatorSet.GenEmptyObj(out ho_Cross);
                            HOperatorSet.GenEmptyObj(out ho_ROI);
                            ho_Image.Dispose();
                            HOperatorSet.ReadImage(out ho_Image, fileNames[index]);    //加载图像
                            HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                            ho_circleContour.Dispose();
                            ho_ROI.Dispose();
                            HTuple hv_cfgPara = new HTuple(250, 255, 50, 200, 1, 0, 1030, 940);//最小灰度，最大灰度，对比度，拟合点数量，sigma，从内向外0，ROI外圆半径，ROI内圆半径
                            halconAlgorithm.GetGuideMoveCoorFit(ho_Image, out ho_circleContour, out ho_ROI, hv_cfgPara, out hv_coor_Row, out hv_coor_Col);
                            //halconAlgorithm.GetGuideMoveCoor(ho_Image, out ho_circleContour, out hv_coor_Row, out hv_coor_Col);
                            if (hv_coor_Row > 0)
                            {
                                this.tB_guideCircle_X.Text = hv_coor_Col.D.ToString();
                                this.tB_guideCircle_Y.Text = hv_coor_Row.D.ToString();
                                halconAlgorithm.ho_AdaptiveImage(hWindowControl5, hv_ImageWidth, hv_ImageHeight);
                                hWindowControl5.HalconWindow.ClearWindow();
                                //HOperatorSet.DispObj(ho_Image, hWindowControl5.HalconWindow);
                                //HOperatorSet.SetColor(hWindowControl5.HalconWindow, "blue");
                               // HOperatorSet.DispObj(ho_circleContour, hWindowControl5.HalconWindow);
                                ho_Cross.Dispose();
                                HOperatorSet.GenCrossContourXld(out ho_Cross, hv_coor_Row, hv_coor_Col, 100, 0.785398);
                                HOperatorSet.SetColor(hWindowControl5.HalconWindow, "red");
                               // HOperatorSet.DispObj(ho_Cross, hWindowControl5.HalconWindow);

                                string str = fileNames[index] + "," + hv_coor_Col.D.ToString() + "," + hv_coor_Row.D.ToString();
                                FileOperate.WriteCSV(0, str);
                            }
                            else
                            {
                               
                                HOperatorSet.DispObj(ho_Image, hWindowControl5.HalconWindow);
                                halconAlgorithm.ho_AdaptiveImage(hWindowControl5, hv_ImageWidth, hv_ImageHeight);
                                
                                MessageBox.Show("没法发现产品");
                                hWindowControl5.HalconWindow.ClearWindow();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        finally
                        {
                            ho_Cross.Dispose();
                            ho_Image.Dispose();
                            ho_circleContour.Dispose();
                        }
                    }
                }
            }
        }

        #region 上相机定位2参数
        private void tn_SeetUpCamLocateFitCircle2_Click(object sender, EventArgs e)
        {
            halconAlgorithm.innerRadius = ProjectInfo.Parameter.innerRadius;
            halconAlgorithm.outerRadius = ProjectInfo.Parameter.outerRadius;

            if (ProjectInfo.Parameter.upCamLocateFitCirclePara2 == null) ProjectInfo.Parameter.upCamLocateFitCirclePara2 = new FitCirclePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//circle.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitCircleForm fitCircleForm = new FitCircleForm(ProjectInfo.Parameter.upCamLocateFitCirclePara2, hv_region);
            fitCircleForm.SetBlobLocate(10, 35, 34, 66);                               //设置blob定位
            fitCircleForm.ShowDialog();
            //fitCircleForm.hv_saveRegion.WriteObject(regionFile);                 //保存roi
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.contrast = fitCircleForm.outFitCirclePara.contrast;
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.fitNum = fitCircleForm.outFitCirclePara.fitNum;
            //ProjectInfo.Parameter.upCamLocateFitCirclePara.ho_ROI = fitCircleForm.outFitCirclePara.ho_ROI;
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.maxGray = fitCircleForm.outFitCirclePara.maxGray;
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.minGray = fitCircleForm.outFitCirclePara.minGray;
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.seekPointPath = fitCircleForm.outFitCirclePara.seekPointPath;
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.sigma = fitCircleForm.outFitCirclePara.sigma;
            ProjectInfo.Parameter.upCamLocateFitCirclePara2.isInheritModel = fitCircleForm.outFitCirclePara.isInheritModel;
            hv_region.Dispose();
        }
        private void btn_SetUpCamLocateFitLine3_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.upCamLocateFitLine1Para2 == null) ProjectInfo.Parameter.upCamLocateFitLine1Para2 = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//line1.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.upCamLocateFitLine1Para2, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.upCamLocateFitLine1Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.upCamLocateFitLine1Para2.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_SetUpCamLocateFitLine4_Click(object sender, EventArgs e)
        {
            if (ProjectInfo.Parameter.upCamLocateFitLine2Para2 == null) ProjectInfo.Parameter.upCamLocateFitLine2Para2 = new FitLinePara();
            HObject hv_region = null;
            HOperatorSet.GenEmptyObj(out hv_region);
            string regionFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//line2.hobj";
            if (File.Exists(regionFile)) hv_region.ReadObject(regionFile);           //读取roi
            FitLineForm fitLineForm = new FitLineForm(ProjectInfo.Parameter.upCamLocateFitLine2Para2, hv_region);
            fitLineForm.ShowDialog();
            fitLineForm.hv_saveRegion.WriteObject(regionFile);
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.contrast = fitLineForm.outFitLinePara.contrast;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.fitNum = fitLineForm.outFitLinePara.fitNum;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.grayTransition = fitLineForm.outFitLinePara.grayTransition;
            //ProjectInfo.Parameter.upCamLocateFitLine2Para.ho_ROI = fitLineForm.outFitLinePara.ho_ROI;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.LSAngle = fitLineForm.outFitLinePara.LSAngle;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.LSJudge = fitLineForm.outFitLinePara.LSJudge;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.pointPosition = fitLineForm.outFitLinePara.pointPosition;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.sigma = fitLineForm.outFitLinePara.sigma;
            ProjectInfo.Parameter.upCamLocateFitLine2Para2.isInheritModel = fitLineForm.outFitLinePara.isInheritModel;
            hv_region.Dispose();
        }

        private void btn_loadImageAndProcess2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件(*.jpg,*.tif,*.bmp,*.Png)|*.jpg;*.tif;*.bmp;*.Png";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                halconAlgorithm.innerRadius = ProjectInfo.Parameter.innerRadius;
                halconAlgorithm.outerRadius = ProjectInfo.Parameter.outerRadius;

                this.tB_upCamImagePath2.Text = openFileDialog.FileName;
                HObject ho_Image = null;
                HObject ho_fitCircleContour = null;
                HObject ho_fitLine1Contour = null;
                HObject ho_fitLine2Contour = null;
                HObject ho_fitAngleLine = null;
                HTuple hv_ImageWidth, hv_ImageHeight = null;
                HOperatorSet.GenEmptyObj(out ho_Image);
                ho_Image.Dispose();
                HOperatorSet.ReadImage(out ho_Image, openFileDialog.FileName);    //加载图像
                HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                double circle_X = 0;
                double circle_Y = 0;
                double lineCorner_X = 0;
                double lineCorner_Y = 0;
                double angle = 0;
                string bugInfo = "";
                //int countROI = 0;
                HObject upCamROI_circle = null;
                HObject upCamROI_line1 = null;
                HObject upCamROI_line2 = null;
                HOperatorSet.GenEmptyObj(out upCamROI_circle);
                HOperatorSet.GenEmptyObj(out upCamROI_line1);
                HOperatorSet.GenEmptyObj(out upCamROI_line2);
                string upCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//circle.hobj";
                if (File.Exists(upCircleFile)) upCamROI_circle.ReadObject(upCircleFile);           //读取roi
                else
                {
                    MessageBox.Show("上相机circleRegion为空！");
                    return;
                }
                string upLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//line1.hobj";
                if (File.Exists(upLine1File)) upCamROI_line1.ReadObject(upLine1File);            //读取roi
                else
                {
                    MessageBox.Show("上相机line1Region为空！");
                    return;
                }

                string upLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//line2.hobj";
                if (File.Exists(upLine2File)) upCamROI_line2.ReadObject(upLine2File);            //读取roi
                else
                {
                    MessageBox.Show("上相机line2Region为空！");
                    return;
                }
                double outCircleRadius = 0;

                outCircleRadius = ProjectInfo.Parameter.upCamLocateOutCircleRadius2 / ShareData.upCamPixSize2_Y;       //流道2

                detectTime.Reset();
                detectTime.Start();

                halconAlgorithm.GetCoilPuckLocateROI(ho_Image, out upCamROI_circle);
                if (halconAlgorithm.GetPuckPosition(ho_Image, ProjectInfo.Parameter.upCamLocateFitCirclePara2,
                    ProjectInfo.Parameter.upCamLocateFitLine1Para2, ProjectInfo.Parameter.upCamLocateFitLine2Para2,
                    upCamROI_circle, upCamROI_line1, upCamROI_line2, ProjectInfo.Parameter.upCamLocateOutCircleRadius2 / ShareData.upCamPixSize2,
                    ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi2, ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi2,
                    out ho_fitCircleContour, out ho_fitLine1Contour, out ho_fitLine2Contour,
                    out ho_fitAngleLine, out circle_X, out circle_Y, out lineCorner_X, out lineCorner_Y, out angle, out bugInfo))
                {
                    halconAlgorithm.ho_AdaptiveImage(hWindowControl_upCam2, hv_ImageWidth, hv_ImageHeight);
                    hWindowControl_upCam2.HalconWindow.ClearWindow();
                    HOperatorSet.DispObj(ho_Image, hWindowControl_upCam2.HalconWindow);
                    HOperatorSet.SetColor(hWindowControl_upCam2.HalconWindow, "blue");
                    HOperatorSet.DispObj(ho_fitAngleLine, hWindowControl_upCam2.HalconWindow);
                    HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl_upCam2.HalconWindow);
                    HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl_upCam2.HalconWindow);
                    HOperatorSet.DispObj(ho_fitLine2Contour, hWindowControl_upCam2.HalconWindow);
                    this.tB_upLocatePoint_X2.Text = circle_X.ToString("f3");
                    this.tB_upLocatePoint_Y2.Text = circle_Y.ToString("f3");
                    this.tB_upLocateAngle2.Text = angle.ToString("f3");
                }
                else
                {
                    MessageBox.Show("检测失败！" + bugInfo);
                }
                ho_Image.Dispose();
                ho_fitAngleLine.Dispose();
                ho_fitCircleContour.Dispose();
                ho_fitLine1Contour.Dispose();
                ho_fitLine2Contour.Dispose();
                detectTime.Stop();
                this.tB_upCamDetectTime2.Text = detectTime.ElapsedMilliseconds.ToString();
            }
        }

        private void btn_testUpFolderImage2_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                halconAlgorithm.innerRadius = ProjectInfo.Parameter.innerRadius;
                halconAlgorithm.outerRadius = ProjectInfo.Parameter.outerRadius;

                //this.tB_savePath.Text = folderBrowserDialog1.SelectedPath;                
                string selectPath = folderBrowserDialog1.SelectedPath;
                string dataPath = selectPath + "\\data.csv";
                StreamWriter swite = new StreamWriter(dataPath, true);
                HObject ho_Image = null;
                // Local control variables 
                HTuple hv_ImageFiles = new HTuple(), hv_Index = new HTuple();
                // Initialize local and output iconic variables 
                HOperatorSet.GenEmptyObj(out ho_Image);
                //Image Acquisition 01: Code generated by Image Acquisition 01
                hv_ImageFiles.Dispose();
                HOperatorSet.ListFiles(selectPath, (new HTuple("files")).TupleConcat(
                    "follow_links"), out hv_ImageFiles);
                {
                    HTuple ExpTmpOutVar_0;
                    HOperatorSet.TupleRegexpSelect(hv_ImageFiles, (new HTuple("\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$")).TupleConcat(
                        "ignore_case"), out ExpTmpOutVar_0);
                    hv_ImageFiles.Dispose();
                    hv_ImageFiles = ExpTmpOutVar_0;
                }
                for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_ImageFiles.TupleLength()
                    )) - 1); hv_Index = (int)hv_Index + 1)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Image.Dispose();
                        HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_Index));
                        HObject ho_fitCircleContour = null;
                        HObject ho_fitLine1Contour = null;
                        HObject ho_fitLine2Contour = null;
                        HObject ho_fitAngleLine = null;
                        HTuple hv_ImageWidth, hv_ImageHeight = null;
                        HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
                        double circle_X = 0;
                        double circle_Y = 0;
                        double lineCorner_X = 0;
                        double lineCorner_Y = 0;
                        double angle = 0;
                        string bugInfo = "";
                        //int countROI = 0;
                        HObject upCamROI_circle = null;
                        HObject upCamROI_line1 = null;
                        HObject upCamROI_line2 = null;
                        HOperatorSet.GenEmptyObj(out upCamROI_circle);
                        HOperatorSet.GenEmptyObj(out upCamROI_line1);
                        HOperatorSet.GenEmptyObj(out upCamROI_line2);
                        string upCircleFile = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//circle.hobj";
                        if (File.Exists(upCircleFile)) upCamROI_circle.ReadObject(upCircleFile);           //读取roi
                        else
                        {
                            MessageBox.Show("上相机circleRegion为空！");
                            return;
                        }
                        string upLine1File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//line1.hobj";
                        if (File.Exists(upLine1File)) upCamROI_line1.ReadObject(upLine1File);            //读取roi
                        else
                        {
                            MessageBox.Show("上相机line1Region为空！");
                            return;
                        }

                        string upLine2File = Path.Combine(System.Environment.CurrentDirectory, "region", "upCam2") + "//line2.hobj";
                        if (File.Exists(upLine2File)) upCamROI_line2.ReadObject(upLine2File);            //读取roi
                        else
                        {
                            MessageBox.Show("上相机line2Region为空！");
                            return;
                        }
                        double outCircleRadius = 0;
                        outCircleRadius = ProjectInfo.Parameter.upCamLocateOutCircleRadius2 / ShareData.upCamPixSize2_Y;
                        //流道2
                        detectTime.Reset();
                        detectTime.Start();

                        halconAlgorithm.GetCoilPuckLocateROI(ho_Image, out upCamROI_circle);
                        if (halconAlgorithm.GetPuckPosition(ho_Image, ProjectInfo.Parameter.upCamLocateFitCirclePara2,
                            ProjectInfo.Parameter.upCamLocateFitLine1Para2, ProjectInfo.Parameter.upCamLocateFitLine2Para2,
                            upCamROI_circle, upCamROI_line1, upCamROI_line2, ProjectInfo.Parameter.upCamLocateOutCircleRadius2 / ShareData.upCamPixSize2,
                            ProjectInfo.Parameter.upCamLocateSeekCornerStartPhi2, ProjectInfo.Parameter.upCamLocateSeekCornerEndPhi2,
                            out ho_fitCircleContour, out ho_fitLine1Contour, out ho_fitLine2Contour,
                            out ho_fitAngleLine, out circle_X, out circle_Y, out lineCorner_X, out lineCorner_Y, out angle, out bugInfo))
                        {
                            halconAlgorithm.ho_AdaptiveImage(hWindowControl_upCam2, hv_ImageWidth, hv_ImageHeight);
                            hWindowControl_upCam2.HalconWindow.ClearWindow();
                            HOperatorSet.DispObj(ho_Image, hWindowControl_upCam2.HalconWindow);
                            HOperatorSet.SetColor(hWindowControl_upCam2.HalconWindow, "blue");
                            HOperatorSet.DispObj(ho_fitAngleLine, hWindowControl_upCam2.HalconWindow);
                            HOperatorSet.DispObj(ho_fitCircleContour, hWindowControl_upCam2.HalconWindow);
                            HOperatorSet.DispObj(ho_fitLine1Contour, hWindowControl_upCam2.HalconWindow);
                            HOperatorSet.DispObj(ho_fitLine2Contour, hWindowControl_upCam2.HalconWindow);
                            this.tB_upLocatePoint_X2.Text = circle_X.ToString("f2");
                            this.tB_upLocatePoint_Y2.Text = circle_Y.ToString("f2");
                            this.tB_upLocateAngle2.Text = angle.ToString("f2");

                            swite.Write(circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3"));
                            swite.WriteLine();
                        }
                        else
                        {
                            MessageBox.Show("检测失败！" + bugInfo);
                        }
                        ho_Image.Dispose();
                        ho_fitAngleLine.Dispose();
                        ho_fitCircleContour.Dispose();
                        ho_fitLine1Contour.Dispose();
                        ho_fitLine2Contour.Dispose();
                        detectTime.Stop();
                        this.tB_upCamDetectTime2.Text = detectTime.ElapsedMilliseconds.ToString();

                        string str = hv_ImageFiles.TupleSelect(hv_Index) + "," + circle_X.ToString("f3") + "," + circle_Y.ToString("f3") + "," + angle.ToString("f3");
                        FileOperate.WriteCSV(1, str);
                    }
                    //Image Acquisition 01: Do something
                }
                swite.Flush();
                swite.Close();
                ho_Image.Dispose();
            }
        }
        #endregion


    }
}
